# 使用 Maven 镜像构建
FROM maven:3.6.0-jdk-11-slim as build

# 设置工作目录
WORKDIR /app

# 先复制 pom 文件
COPY pom.xml .
COPY twotwo-shop-common/pom.xml twotwo-shop-common/
COPY twotwo-shop-model/pom.xml twotwo-shop-model/
COPY twotwo-shop-service/pom.xml twotwo-shop-service/
COPY twotwo-shop-feign-api/pom.xml twotwo-shop-feign-api/
COPY twotwo-shop-utils/pom.xml twotwo-shop-utils/
COPY twotwo-shop-gateway/pom.xml twotwo-shop-gateway/

# 复制源代码
COPY twotwo-shop-common/src twotwo-shop-common/src/
COPY twotwo-shop-model/src twotwo-shop-model/src/
COPY twotwo-shop-service/src twotwo-shop-service/src/
COPY twotwo-shop-feign-api/src twotwo-shop-feign-api/src/
COPY twotwo-shop-utils/src twotwo-shop-utils/src/
COPY twotwo-shop-gateway/src twotwo-shop-gateway/src/

# Maven 构建
RUN mvn clean package -DskipTests

# 使用 JDK 运行时镜像
FROM openjdk:11-jre-slim

WORKDIR /app

# 复制构建产物
COPY --from=build /app/twotwo-shop-gateway/twotwo-shop-gateway-user/target/*.jar app.jar

# 暴露端口
EXPOSE 9090

# 启动命令
ENTRYPOINT ["java","-jar","app.jar"]